package com.example.amqp.controller;

import com.example.amqp.constant.MqConstant;
import com.example.amqp.service.Produce;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2021/2/11 10:59
 */
@RestController
@RequestMapping("/delayQueue")
public class DelayQueueController
{
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private Produce produce;

    @GetMapping("/send/{time}")
    public String send(@PathVariable("time") int time)
    {
        log.info("{}秒后, 发送延迟消息，当前时间{}", time, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        produce.send("我是延时消息...", time, MqConstant.MY_QUEUE_ONE);
        return "ok";
    }
}
